from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
driver.get("http://sahitest.com/demo/selectTest.htm")
driver.maximize_window()
driver.implicitly_wait(15)
# 第一种方式：根据下标选择下拉框
"""
s1Id = driver.find_element(By.ID,"s1Id") #先顶为到下拉框
select_index = Select(s1Id)
select_index.select_by_index(2)
"""
# 第二种方式：根据value选择
"""
s2Id = driver.find_element(By.ID,"s2Id") # 先定位到下拉框元素
select_value = Select(s2Id) # 实例化对象
select_value.select_by_value("o1")
"""
# 第三种方式：根据手动输入选择
"""
s1 = driver.find_element(By.ID,"s1")
select_input = Select(s1)
select_input.select_by_visible_text("Business Phone")
"""